package com.qianyucc.blog.config;

import com.github.xiaoymin.knife4j.spring.annotations.*;
import org.springframework.context.annotation.*;
import org.springframework.core.env.*;
import springfox.documentation.builders.*;
import springfox.documentation.service.*;
import springfox.documentation.spi.*;
import springfox.documentation.spring.web.plugins.*;
import springfox.documentation.swagger2.annotations.*;

import java.util.*;

/**
 * @author lijing
 * @e-mail 1413979079@qq.com
 * @date 2020-02-08 16:30
 * @description Swagger配置类
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUi
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment) {
        // 如果在dev环境（开发环境）就开启Swagger
        boolean isDev = environment.acceptsProfiles(Profiles.of("dev"));
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("芊雨")
                .enable(isDev)
                .select()
                // 配置需要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.qianyucc.blog.controller"))
                // 配置需要匹配的路径
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    // 配置Swagger的ApiInfo
    private ApiInfo apiInfo() {
        // 作者信息
        Contact contact = new Contact("芊雨", "http://www.qianyucc.xyz/", "1413979079@qq.com");
        return new ApiInfo(
                "博客API接口文档",
                "芊雨的博客后端所有的api接口",
                "v1.0.0",
                "http://localhost:8886/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
